package org.chandler.ccgp.parser;


import org.chandler.ccgp.data.Task;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class TaskParser {
	public static Task homeParser(String html, Task t){
		Document doc = Jsoup.parse(html);
		//解析查询结果总条数
		t.totalNum = getTotalNum(doc);
		//解析查询结果总页数
		t.totalPage = t.totalNum / 20 + (t.totalNum % 20 == 0 ? 0 : 1);
		return t;
	}
	
	
	/**
	 * 解析查询结果总条数
	 * @param doc
	 * @return
	 */
	private static int getTotalNum(Document doc){
		int totalNum = 0;
		Elements es = doc.select("[style=\"color:#c00000\"]");
		if(es != null & es.size() > 0){
			totalNum = Integer.valueOf(es.first().text().trim());
		}
		return totalNum;
	}
}
